<!DOCTYPE html>
<html lang="en">

<head>
    <#include "/dk/app/components/meta.html" />
    <title>蓝天运动 ${metaTitleSuffix!}</title>
    <#include "/dk/app/components/stylesheets.html" />
    <link rel="stylesheet" href="/dk/app/stylesheets/index.css?v=2">
</head>

<body>
    <div id="app">
        <div class="logo">
            <img src="https://i.loli.net/2018/12/28/5c26413b42ffe.jpg" class="am-img-responsive" style="max-height: 100px" />
        </div>
        <div class="login-form" style="margin: 0 auto; width: 50%; min-width: 700px;">
            <div class="login-form-field">
                <div class="login-form-field-icon">
                    <img src="/dk/app/assets/img/icon-user.png" class="am-img-responsive" />
                </div>
                    <div class="login-form-field-input">
                        <input type="text" v-model="account" placeholder="账号" />
                    </div>
                </div>
                <div class="login-form-field">
                    <div class="login-form-field-icon">
                        <img src="/dk/app/assets/img/icon-pwd.png" class="am-img-responsive" />
                </div>
                        <div class="login-form-field-input">
                            <input type="password" v-model="password" placeholder="密码" @keyup.enter="login" />
                        </div>
                    </div>
                    <div class="login-form-submit">
                        <button class="am-btn theme-background-color1" @click="login">登录</button>
                    </div>
                </div>
                <footer style="width: 50%; min-width: 700px; height: 60px; padding: 20px 3rem; margin: 0 auto;">
                    <p>由 <a href="http://www.zhen-yee.com/" title="蓁奕科技" target="_blank" style="color: rgb(14, 144, 210);">蓁奕科技</a> 提供技术支持 CopyRight©2018 Zhenyi Tech Inc.</p>
                </footer>
            </div>
        </div>
    </div>
    <#include "/dk/app/components/scripts.html" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9/crypto-js.min.js"></script>
    <script type="text/javascript">
    var app = new Vue({
        el: '#app',
        data() {
            return {
                account: '',
                password: ''
            }
        },
        mounted: function() {},
        methods: {
            login() {
                var self = this;
                var encoded = self.aesCBC(self.password);
                var param = Qs.stringify({
                    account: self.account,
                    password: encoded
                });
                var layerIndex = layer.open({ type: 2, shadeClose: false });
                axios({
                        url: '/dk/admin/auth',
                        method: 'post',
                        data: param,
                        headers: {
                            'Content-Type': 'application/x-www-form-urlencoded'
                        }
                    })
                    .then(function(response) {
                        if (response.data.status == 200) {
                            var loginUrl = response.data.info
                            var url = "${URL!''}"
                            if (url != '') {
                                window.location.href = url;
                                return;
                            } else {
                                window.location.href = loginUrl;
                                return;
                            }
                            // msg("登录成功");
                        } else {
                            layer.open({
                                content: "登录失败：" + response.data.msg,
                                skin: 'msg',
                                time: 5 //2秒后自动关闭
                            });
                            console.log(response.data);
                        }
                        layer.close(layerIndex);
                    })
                    .catch(function(error) {
                        layer.open({
                            content: "登录失败",
                            skin: 'msg',
                            time: 5 //2秒后自动关闭
                        });
                        console.log(error);
                        layer.close(layerIndex);
                    });
            },
            aesCBC(text) {
                var aesText = text;
                var key = CryptoJS.enc.Utf8.parse('${key!}');
                var iv = CryptoJS.enc.Utf8.parse('RandomInitVector');
                aesText = CryptoJS.AES.encrypt(text, key, {
                    iv: iv,
                    mode: CryptoJS.mode.CBC,
                    padding: CryptoJS.pad.Pkcs7
                }).toString();
                return aesText;
            }
        }
    })
    </script>
    <script>
    // wx.ready(function() {
    //     initWXShare()
    // })
    </script>
</body>

</html>